package com.bjwl.web.contrlller.branchstore;

import com.bjwl.pojo.Bsadmin;
import com.bjwl.pojo.Orders;
import com.bjwl.pojo.vo.TimerQueryVo;
import com.bjwl.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

/**
 * @Author: dzx
 * @Date:Create：in 2020/5/14 17:24
 * @Description:
 * @Modified By：
 * @Version: 1.0
 */
@Controller
@RequestMapping("/Or")
public class TimerController {



    @Autowired
    private OrdersService ordersService;

    @RequestMapping("/getTimer")
    public @ResponseBody
    Boolean getTimer(HttpSession httpSession){
        Bsadmin bsadmin = (Bsadmin) httpSession.getAttribute("bsadmin1");
        if(bsadmin != null){
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = Calendar.getInstance();
            TimerQueryVo timerQueryVo = new TimerQueryVo();
            calendar.add(Calendar.DATE, 0);
            timerQueryVo.setStartDate(df.format(calendar.getTime()));
            calendar.add(Calendar.DATE, +3);
            timerQueryVo.setEndDate(df.format(calendar.getTime()));
            timerQueryVo.setBsid(bsadmin.getBsid());
            List<Orders> list = ordersService.findOrdersJob(timerQueryVo);
            if(list != null && list.size() > 0){
                return true;
            }
        }
        return false;
    }

    @RequestMapping("/findAlltimerOrders")
    public String findAlltimerOrders(HttpSession httpSession, Model model){
        Bsadmin bsadmin = (Bsadmin) httpSession.getAttribute("bsadmin1");
        if(bsadmin != null){
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = Calendar.getInstance();
            TimerQueryVo timerQueryVo = new TimerQueryVo();
            calendar.add(Calendar.DATE, 0);
            timerQueryVo.setStartDate(df.format(calendar.getTime()));
            calendar.add(Calendar.DATE, +3);
            timerQueryVo.setEndDate(df.format(calendar.getTime()));
            timerQueryVo.setBsid(bsadmin.getBsid());
            List<Orders> list = ordersService.findOrdersJob(timerQueryVo);
            model.addAttribute("timerOrders",list);
        }
        return "branch_oa/timeOrder-list";
    }

}
